#include "GrMPEFrame.h"
#include "OperatingModelPanel.h"
#include "MPEPanel.h"
//#include "GrMPEPlot.h"

GrMPEFrame::GrMPEFrame(const wxString& title, int xpos, int ypos, int width, int height)
          : wxFrame(NULL,
                    wxID_ANY,
                    title,
                    wxPoint(xpos, ypos),
                    wxSize(width, height))
{

  m_pMenuBar = new wxMenuBar();

  m_pFileMenu = new wxMenu();
  m_pFileMenu->Append(wxID_NEW, wxT("&New"), wxT("Create a new MPE"));
  m_pFileMenu->Append(wxID_OPEN, wxT("&Open"), wxT("Opens an existing MPE"));
  m_pFileMenu->Append(wxID_CLOSE, wxT("&Close"), wxT("Close MPE"));
  m_pFileMenu->Append(wxID_SAVE, wxT("&Save"), wxT("Save the MPE"));
  m_pFileMenu->Append(wxID_SAVEAS, wxT("Save &As"), wxT("Save the MPE as.."));
  m_pFileMenu->AppendSeparator();
  m_pFileMenu->Append(wxID_EXIT, wxT("&Quit"), wxT("Quit the application"));
  m_pMenuBar->Append(m_pFileMenu, wxT("&File"));

  m_pHelpMenu = new wxMenu();
  m_pHelpMenu->Append(wxID_ABOUT, wxT("&About"), wxT("Shows information about the application"));
  m_pMenuBar->Append(m_pHelpMenu, wxT("&Info"));

  m_pPlotMenu = new wxMenu();
  m_pPlotMenu->Append(ID_PLOT,  wxT("Plot window"), wxT("Open the plotting window"));
  m_pMenuBar->Append(m_pPlotMenu, wxT("&Plot"));
  SetMenuBar(m_pMenuBar);

  CreateStatusBar(3);
  SetStatusText(wxT("Ready"), 0);

  m_pFrameSizer = new wxBoxSizer(wxVERTICAL);
  m_pNotebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP);
  m_pMPEPanel = new MPEPanel(m_pNotebook);
  m_pOMPanel = new OperatingModelPanel(m_pNotebook);

  m_pNotebook->AddPage(m_pMPEPanel, wxT(TAB0_LABEL));
  m_pNotebook->AddPage(m_pOMPanel, wxT(TAB1_LABEL));

  m_pFrameSizer->Add(m_pNotebook, wxSizerFlags(1).Expand().Border(wxALL,BORDER_SIZE));
  SetSizerAndFit(m_pFrameSizer);
}


void GrMPEFrame::OpenPlot(wxCommandEvent& event)
{
  //m_pPlotFrame = new MyFrame();
  //wxInitAllImageHandlers();
  //m_pPlotFrame->Show( TRUE );

}

//void GrMPEFrame::NewFile(wxCommandEvent& WXUNUSED(event))
void GrMPEFrame::NewFile(wxCommandEvent& event)
{
  /*
  CloseFile(event);
  wxString nullString = wxString::FromUTF8(NULL_STRING);
  placeLabel(m_pScenarioLabel, nullString);
  placeLabel(m_pHCRLabel, nullString);
  placeLabel(m_pGearsLabel, nullString);
  placeGrid(m_pScenarioGrid, nullString);
  placeGrid(m_pHCRGrid, nullString);
  placeGrid(m_pGearsGrid, nullString);

  // reset the path of our current open file
  m_pCurrentDocPath = nullString;

  // Set the Title to reflect the file open
  SetTitle(wxString::FromUTF8(PROGRAM_NAME) << wxString::FromUTF8(" - untitled *"));
*/
}

void GrMPEFrame::OpenFile(wxCommandEvent& WXUNUSED(event))
{
  /*
  wxString currDir = wxGetCwd();
  wxFileDialog *OpenDialog = new wxFileDialog(this,
                                              wxT("Choose a file to open"),
                                              currDir, wxEmptyString,
                                              wxT("MPE files (*.mpe)|*.mpe"),
                                              wxFD_OPEN, wxDefaultPosition);
  if (OpenDialog->ShowModal() == wxID_OK)
  */
  /*
  if(1)
  {
    //m_pMasterFile = OpenDialog->GetPath();
    //loadMPE(m_pMasterFile);

    m_pMainBoxSizer->Add(m_pMPEFlexGridSizer,
                         0,
                         wxEXPAND,
                         0);
    SetSizerAndFit( m_pMainBoxSizer );
    SetTitle(wxString::FromUTF8(PROGRAM_NAME)); //  << wxString::FromUTF8(" - ") << OpenDialog->GetFilename());
  }
*/
}

void GrMPEFrame::CloseFile( wxCommandEvent& event )
{
  /*
  // This stuff is for closing when user presses 'X', not menu close
  if ( event.CanVeto() ){ //&& m_bFileNotSaved ){
    if ( wxMessageBox(wxT("The file has not been saved... continue closing?"),
                      wxT("Please confirm"),
                      wxICON_QUESTION | wxYES_NO) != wxYES ){
      event.Veto();
      return;
    }
  }
  // you may also do:  event.Skip();
  // since the default event handler does call Destroy(), too
*/
  //m_pOMPanel->Destroy();
  //Destroy();


  // Delete all objects in GrMPEFrame
  this->SetSize(DEFAULT_WINDOW_X_SIZE,DEFAULT_WINDOW_Y_SIZE);
}

GrMPEFrame::~GrMPEFrame()
{
}

BEGIN_EVENT_TABLE ( GrMPEFrame, wxFrame )
  EVT_MENU(wxID_NEW, GrMPEFrame::NewFile)
  EVT_MENU(wxID_OPEN, GrMPEFrame::OpenFile)
  EVT_MENU(wxID_CLOSE, GrMPEFrame::CloseFile)
  EVT_MENU(ID_PLOT, GrMPEFrame::OpenPlot)
// EVT_MENU(wxID_SAVE, GrMPEFrame::SaveFile)
// EVT_MENU(wxID_SAVEAS, GrMPEFrame::SaveFileAs)
// EVT_MENU(wxID_EXIT, GrMPEFrame::Quit)
END_EVENT_TABLE()
